﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Code;
using System.Data;

namespace E2_WEBSITE.Code.RAM
{
    public class RamDataAccess
    {
        private DataProvider m_DataProvider = DataProvider.GlobalDataProvider;

        public List<string> GetListBusByManufactureName(string sManuName)
        {

            List<string> lstBus = new List<string>();
            string sSql = "select distinct bus from RAM,SAN_PHAM,NHA_SAN_XUAT where SAN_PHAM.idNSX = NHA_SAN_XUAT.id AND NHA_SAN_XUAT.TenNSX = '" + sManuName
            + "' AND SAN_PHAM.id=RAM.id";

            DataTable dt = m_DataProvider.ExecuteQueryDataTable(sSql);
            if (dt != null)
            {
                int iCount = dt.Rows.Count;
                for (int i = 0; i < iCount; i++)
                {
                    lstBus.Add(dt.Rows[i][0].ToString());
                }
            }
            return lstBus;
        }   

        public List<string> GetListMemoryByManufactureAndBus(string sManuFacture, string sBus)
        {
            List<string> lstMemory = new List<string>();
            string sSql = "select distinct DUNGLUONG from RAM,SAN_PHAM,NHA_SAN_XUAT where SAN_PHAM.idNSX = NHA_SAN_XUAT.id AND NHA_SAN_XUAT.TenNSX = '" + sManuFacture
            + "' AND BUS ='" + sBus +"' AND SAN_PHAM.id=RAM.id";

            DataTable dt = m_DataProvider.ExecuteQueryDataTable(sSql);
            if (dt != null)
            {
                int iCount = dt.Rows.Count;
                for (int i = 0; i < iCount; i++)
                {
                    lstMemory.Add(dt.Rows[i][0].ToString());
                }
            }
            return lstMemory;
        }

        public List<string> GetListRamNameByManufactureAndBusAndMemory(string sManufacture,string sBus,string sMemory)
        {
            List<string> lstProName = new List<string>();
            string sSql = "select distinct TENSANPHAM from RAM,SAN_PHAM,NHA_SAN_XUAT where SAN_PHAM.idNSX = NHA_SAN_XUAT.id AND NHA_SAN_XUAT.TenNSX = '" + sManufacture
            + "' AND BUS ='" + sBus + "'AND DUNGLUONG ='" + sMemory + "'AND SAN_PHAM.id=RAM.id";

            DataTable dt = m_DataProvider.ExecuteQueryDataTable(sSql);
            if (dt != null)
            {
                int iCount = dt.Rows.Count;
                for (int i = 0; i < iCount; i++)
                {
                    lstProName.Add(dt.Rows[i][0].ToString());
                }
            }
            return lstProName;

        }

        public int GetRamIDByManuAndBusAndMemoryAndName(string sManufacture,string sBus,string sMemory,string sName)
        {
            int iID = -1;
            string sSql = "select distinct SAN_PHAM.ID from RAM,SAN_PHAM,NHA_SAN_XUAT where SAN_PHAM.idNSX = NHA_SAN_XUAT.id AND NHA_SAN_XUAT.TenNSX = '" + sManufacture
            + "' AND BUS ='" + sBus + "'AND DUNGLUONG ='" + sMemory + "' AND TENSANPHAM ='" + sName +"'AND SAN_PHAM.id=RAM.id";

            DataTable dt = m_DataProvider.ExecuteQueryDataTable(sSql);
            if (dt != null)
            {
                iID= int.Parse(dt.Rows[0][0].ToString());             
            }
            return iID;
        }

    }
}
